package com.jpro.framework.jackson.serializer;


import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

import java.io.IOException;

// 脱敏序列化逻辑
public class DesensitizeSerializer extends JsonSerializer<String> {
    @Override
    public void serialize(String value, JsonGenerator gen, SerializerProvider provider)
            throws IOException {

        if (value == null) {
            gen.writeNull();
            return;
        }
        // 脱敏规则示例：保留前3后4位
        String masked = "****";
        if(value.length()>10){
             masked = value.substring(0, 3)+ "****" + value.substring(value.length() - 4);
        }
        gen.writeString(masked);
    }
}
